<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="日期" prop="date" >
        <el-date-picker
          v-model="daterangeDate"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="星期" prop="weekList">
        <el-select v-model="queryParams.weekList" placeholder="请选择星期" multiple="true" clearable style="width:100px">
          <el-option
            v-for="dict in dict.type.week_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="地区">
        <el-select v-model="queryParams.province" placeholder="省" @change="getCityList" clearable style="width:100px">
          <el-option value="">省</el-option>
          <el-option
            v-for="item in provinceList"
            :key="item.id"
            :label="item.province"
            :value="item.provinceid"
          >
          </el-option>
        </el-select>
        <el-select v-model="queryParams.city" placeholder="市" @change="getAreaList" clearable style="width:100px">
          <el-option value="">市</el-option>
          <el-option
            v-for="item in cityList"
            :key="item.id"
            :label="item.city"
            :value="item.cityid"
          >
          </el-option>
        </el-select>
        <el-select v-model="queryParams.area" placeholder="区/县" clearable style="width:100px">
          <el-option value="">区/县</el-option>
          <el-option
            v-for="item in areaList"
            :key="item.id"
            :label="item.area"
            :value="item.areaid"
          >
          </el-option>
        </el-select>

      </el-form-item>
      <el-form-item label="选择门店">
        <el-select v-model="queryParams.storeId" placeholder="请选择门店" prop="storeId" @change="handleQuery" clearable>
          <el-option value="">全部门店</el-option>
          <el-option
            v-for="item in device_infoList"
            :key="item.id"
            :label="item.company"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['energize:daliySalesReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['energize:daliySalesReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['energize:daliySalesReport:remove']"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energize:daliySalesReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="daliySalesReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键自增ID" align="center" prop="id" />
      <el-table-column label="日期：年-月-日" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="星期" align="center" prop="week">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.week_type" :value="scope.row.week"/>
        </template>
      </el-table-column>
      <el-table-column label="门店id" align="center" prop="storeId" />
      <el-table-column label="门店名称" align="center" prop="storeName" />
      <el-table-column label="客户订单总数量" align="center" prop="customerOrderAmount" />
      <el-table-column label="销售总额" align="center" prop="totalSales" />
      <el-table-column label="客户单价" align="center" prop="customerUnitPrice" />
      <el-table-column label="包含烟草客户订单量" align="center" prop="includeCigaretteOrderAmount" />
      <el-table-column label="含烟量销售额占比" align="center" prop="includeCigaretteRatio" />
      <el-table-column label="不包含烟草客户订单量" align="center" prop="notIncludeCigaretteOrderAmount" />
      <el-table-column label="包含烟草销售额" align="center" prop="includeCigaretteOrderSales" />
      <el-table-column label="包含烟草客单价" align="center" prop="includeCigaretteUnitPrice" />
      <el-table-column label="不包含烟草销售额" align="center" prop="notIncludeCigaretteOrderSales" />
      <el-table-column label="不包含烟草客单价" align="center" prop="notIncludeCigaretteUnitPrice" />
      <el-table-column label="烟草销售额" align="center" prop="cigaretteSales" />
      <el-table-column label="纯烟草销售额占比" align="center" prop="cigaretteRatio" />
      <el-table-column label="当日进店客流数量" align="center" prop="intoStoreCustomerNum" />
      <el-table-column label="路过客户数量" align="center" prop="passStoreCustomerNum" />
      <el-table-column label="客户购买率" align="center" prop="buyCustomerRatio" />
      <el-table-column label="客户进店转化率" align="center" prop="intoStoreCustomerRatio" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['energize:daliySalesReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['energize:daliySalesReport:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

<!--     添加或修改门店日销售报表对话框
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期：年-月-日" prop="date">
          <el-date-picker clearable
                          v-model="form.date"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择日期：年-月-日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="星期" prop="week">
          <el-select v-model="form.week" placeholder="请选择星期">
            <el-option
              v-for="dict in dict.type.week_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="门店id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入门店id" />
        </el-form-item>
        <el-form-item label="门店名称" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入门店名称" />
        </el-form-item>
        <el-form-item label="客户订单总数量" prop="customerOrderAmount">
          <el-input v-model="form.customerOrderAmount" placeholder="请输入客户订单总数量" />
        </el-form-item>
        <el-form-item label="销售总额" prop="totalSales">
          <el-input v-model="form.totalSales" placeholder="请输入销售总额" />
        </el-form-item>
        <el-form-item label="客户单价" prop="customerUnitPrice">
          <el-input v-model="form.customerUnitPrice" placeholder="请输入客户单价" />
        </el-form-item>
        <el-form-item label="包含烟草客户订单量" prop="includeCigaretteOrderAmount">
          <el-input v-model="form.includeCigaretteOrderAmount" placeholder="请输入包含烟草客户订单量" />
        </el-form-item>
        <el-form-item label="含烟量销售额占比" prop="includeCigaretteRatio">
          <el-input v-model="form.includeCigaretteRatio" placeholder="请输入含烟量销售额占比" />
        </el-form-item>
        <el-form-item label="不包含烟草客户订单量" prop="notIncludeCigaretteOrderAmount">
          <el-input v-model="form.notIncludeCigaretteOrderAmount" placeholder="请输入不包含烟草客户订单量" />
        </el-form-item>
        <el-form-item label="包含烟草销售额" prop="includeCigaretteOrderSales">
          <el-input v-model="form.includeCigaretteOrderSales" placeholder="请输入包含烟草销售额" />
        </el-form-item>
        <el-form-item label="包含烟草客单价" prop="includeCigaretteUnitPrice">
          <el-input v-model="form.includeCigaretteUnitPrice" placeholder="请输入包含烟草客单价" />
        </el-form-item>
        <el-form-item label="不包含烟草销售额" prop="notIncludeCigaretteOrderSales">
          <el-input v-model="form.notIncludeCigaretteOrderSales" placeholder="请输入不包含烟草销售额" />
        </el-form-item>
        <el-form-item label="不包含烟草客单价" prop="notIncludeCigaretteUnitPrice">
          <el-input v-model="form.notIncludeCigaretteUnitPrice" placeholder="请输入不包含烟草客单价" />
        </el-form-item>
        <el-form-item label="烟草销售额" prop="cigaretteSales">
          <el-input v-model="form.cigaretteSales" placeholder="请输入烟草销售额" />
        </el-form-item>
        <el-form-item label="纯烟草销售额占比" prop="cigaretteRatio">
          <el-input v-model="form.cigaretteRatio" placeholder="请输入纯烟草销售额占比" />
        </el-form-item>
        <el-form-item label="当日进店客流数量" prop="intoStoreCustomerNum">
          <el-input v-model="form.intoStoreCustomerNum" placeholder="请输入当日进店客流数量" />
        </el-form-item>
        <el-form-item label="路过客户数量" prop="passStoreCustomerNum">
          <el-input v-model="form.passStoreCustomerNum" placeholder="请输入路过客户数量" />
        </el-form-item>
        <el-form-item label="客户购买率" prop="buyCustomerRatio">
          <el-input v-model="form.buyCustomerRatio" placeholder="请输入客户购买率" />
        </el-form-item>
        <el-form-item label="客户进店转化率" prop="intoStoreCustomerRatio">
          <el-input v-model="form.intoStoreCustomerRatio" placeholder="请输入客户进店转化率" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->
  </div>
</template>

<script>
import { listDaliySalesReport, getDaliySalesReport, delDaliySalesReport, addDaliySalesReport, updateDaliySalesReport } from "@/api/energize/daliySalesReport";
import { listDevice_info } from "@/api/energize/device_info";
import { listProvince } from "@/api/energize/province";
import { listCity} from "@/api/energize/city";
import { listArea} from "@/api/energize/area";

export default {
  name: "DaliySalesReport",
  dicts: ['week_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      areaList:[],
      cityList:[],
      provinceList:[],
      // 设备信息表格数据
      device_infoList: [],
      // 门店日销售报表表格数据
      daliySalesReportList: [],
      // 客户进店转化率时间范围
      daterangeDate: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: null,
        weekList: null,
        storeId: null,
        province:null,
        city:null,
        area:null,
      },
      provinceQueryParams: {
        pageNum: 1,
        pageSize: 5000,
      },
      cityQueryParams: {
        pageNum: 1,
        pageSize: 5000,
        provinceid: null
      },
      areaQueryParams: {
        pageNum: 1,
        pageSize: 5000,
        cityid: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getProvinceList();
    this.getStoreList();
    this.getList();
  },
  methods: {
    /**
     * 获取省会城市列表
     * */
    getProvinceList(){
      listProvince(this.provinceQueryParams).then(response => {
        this.provinceList = response.rows;
      });
    },
    /** 查询city城市名称列表 */
    getCityList() {
      this.cityQueryParams.provinceid=this.queryParams.province;
      listCity(this.cityQueryParams).then(response => {
        this.cityList = response.rows;
      });
    },
    /** 查询地区表列表 */
    getAreaList() {
      this.areaQueryParams.cityid=this.queryParams.city;
      listArea(this.areaQueryParams).then(response => {
        this.areaList = response.rows;
      });
    },
    /**
     * 查询设备列表
     * */
    getStoreList(){
      listDevice_info().then(response => {
        this.device_infoList = response.rows;
      });
    }
    ,
    /** 查询门店日销售报表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDate && '' != this.daterangeDate) {
        this.queryParams.params["beginDate"] = this.daterangeDate[0];
        this.queryParams.params["endDate"] = this.daterangeDate[1];
      }
      listDaliySalesReport(this.queryParams).then(response => {
        this.daliySalesReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        date: null,
        weekList: null,
        storeId: null,
        storeName: null,
        customerOrderAmount: null,
        totalSales: null,
        customerUnitPrice: null,
        includeCigaretteOrderAmount: null,
        includeCigaretteRatio: null,
        notIncludeCigaretteOrderAmount: null,
        includeCigaretteOrderSales: null,
        includeCigaretteUnitPrice: null,
        notIncludeCigaretteOrderSales: null,
        notIncludeCigaretteUnitPrice: null,
        cigaretteSales: null,
        cigaretteRatio: null,
        intoStoreCustomerNum: null,
        passStoreCustomerNum: null,
        buyCustomerRatio: null,
        intoStoreCustomerRatio: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  /*  /!** 新增按钮操作 *!/
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门店日销售报表";
    },
    /!** 修改按钮操作 *!/
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDaliySalesReport(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门店日销售报表";
      });
    },
    /!** 提交按钮 *!/
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDaliySalesReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDaliySalesReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /!** 删除按钮操作 *!/
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除门店日销售报表编号为"' + ids + '"的数据项？').then(function() {
        return delDaliySalesReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },*/
    /** 导出按钮操作 */
    handleExport() {
      this.download('energize/daliySalesReport/export', {
        ...this.queryParams
      }, `daliySalesReport_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
